package com.work.servlet.student;

import com.work.entities.MyClass;
import com.work.service.UserService;
import com.work.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/10/8.
 */
@WebServlet("/stu_my_class")
public class StuMyClassServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        HttpSession session = req.getSession();

        if (session.getAttribute("isLogin") != null && (Boolean) session.getAttribute("isLogin")) {

            if (session.getAttribute("studentId") != null){

                UserService service = new UserServiceImpl();

                List<MyClass> myClasses = service.stuGetMyClass((Integer) session.getAttribute("studentId"));

                session.setAttribute("myClasses", myClasses);

                req.getRequestDispatcher("student_my_class.jsp").forward(req, resp);

            }

        }else {
            session.setAttribute("error", "请登录后访问");
            resp.sendRedirect("login.jsp");
        }


    }
}
